
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>redis · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="script.html" />
    
    
    <link rel="prev" href="oracle.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    starting
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../INTRODUCTION.html">
            
                <a href="../INTRODUCTION.html">
            
                    
                    introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    algorithm
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../algorithm/graphic_processing/">
            
                <a href="../algorithm/graphic_processing/">
            
                    
                    graphic_processing
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../algorithm/machine_learning/">
            
                <a href="../algorithm/machine_learning/">
            
                    
                    machine_learning
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../algorithm/other/">
            
                <a href="../algorithm/other/">
            
                    
                    other
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    language
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../language/cpp/">
            
                <a href="../language/cpp/">
            
                    
                    cpp
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../language/golang/">
            
                <a href="../language/golang/">
            
                    
                    golang
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../language/java/">
            
                <a href="../language/java/">
            
                    
                    java
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../language/javascript/">
            
                <a href="../language/javascript/">
            
                    
                    javascript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../language/python/">
            
                <a href="../language/python/">
            
                    
                    python
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    soft_skills
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="docker.html">
            
                <a href="docker.html">
            
                    
                    docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="git.html">
            
                <a href="git.html">
            
                    
                    git
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="ideaj.html">
            
                <a href="ideaj.html">
            
                    
                    ideaj
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="linux.html">
            
                <a href="linux.html">
            
                    
                    linux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="maven.html">
            
                <a href="maven.html">
            
                    
                    maven
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="mysql.html">
            
                <a href="mysql.html">
            
                    
                    mysql
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="nginx.html">
            
                <a href="nginx.html">
            
                    
                    nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="node.js.html">
            
                <a href="node.js.html">
            
                    
                    node.js
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9" data-path="oracle.html">
            
                <a href="oracle.html">
            
                    
                    oracle
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.10" data-path="redis.html">
            
                <a href="redis.html">
            
                    
                    redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.11" data-path="script.html">
            
                <a href="script.html">
            
                    
                    script
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.12" data-path="skill.html">
            
                <a href="skill.html">
            
                    
                    skill
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.13" data-path="tcp-ip.html">
            
                <a href="tcp-ip.html">
            
                    
                    tcp-ip
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.14" data-path="ubuntu.html">
            
                <a href="ubuntu.html">
            
                    
                    ubuntu
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.15" data-path="vscode.html">
            
                <a href="vscode.html">
            
                    
                    vscode
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.16" data-path="windows.html">
            
                <a href="windows.html">
            
                    
                    windows
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >redis</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
                                <section class="normal markdown-section">
                                
                                <h3 id="1-windows-&#x5B89;&#x88C5;">1. <a href="https://github.com/microsoftarchive/redis/releases" target="_blank">Windows &#x5B89;&#x88C5;</a></h3>
<pre><code class="lang-bat"><span class="hljs-comment">@REM &#x5B89;&#x88C5;</span>
redis-server.exe --service-install redis.windows.conf --loglevel verbose

<span class="hljs-comment">@REM &#x5378;&#x8F7D;&#x670D;&#x52A1;</span>
redis-server --service-uninstall

<span class="hljs-comment">@REM &#x5F00;&#x542F;&#x670D;&#x52A1;</span>
redis-server --service-<span class="hljs-built_in">start</span>

<span class="hljs-comment">@REM &#x505C;&#x6B62;&#x670D;&#x52A1;</span>
redis-server --service-stop

<span class="hljs-comment">@REM &#x91CD;&#x547D;&#x540D;&#x670D;&#x52A1;</span>
redis-server --service-name <span class="hljs-variable">%NAME%</span>
</code></pre>
<h3 id="2-&#x6570;&#x636E;&#x7ED3;&#x6784;">2. &#x6570;&#x636E;&#x7ED3;&#x6784;</h3>
<p>Redis&#x652F;&#x6301;&#x4E94;&#x79CD;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF1A;string&#xFF08;&#x5B57;&#x7B26;&#x4E32;&#xFF09;&#xFF0C;hash&#xFF08;&#x54C8;&#x5E0C;&#xFF09;&#xFF0C;list&#xFF08;&#x5217;&#x8868;&#xFF09;&#xFF0C;set&#xFF08;&#x96C6;&#x5408;&#xFF09;&#x53CA; zset&#xFF08;sorted set&#xFF1A;&#x6709;&#x5E8F;&#x96C6;&#x5408;&#xFF09;</p>
<p>Redis &#x662F; 32 &#x4F4D;&#x5B58;&#x50A8;&#x7684;, &#x6240;&#x4EE5; string &#x7684;&#x503C;&#x6700;&#x5927;&#x4E3A; </p>
<blockquote>
<p>$(2^{32} - 1)bit \approx 512MB$</p>
</blockquote>
<p>&#x5176;&#x4ED6;&#x5982; hash, list, set, zset &#x7684;&#x952E;&#x6216;&#x5143;&#x7D20;&#x7684;&#x6700;&#x5927;&#x4E2A;&#x6570;&#x4E5F;&#x662F;&#x4E00;&#x6837;</p>
<ul>
<li>string</li>
</ul>
<pre><code class="lang-sh">&gt; <span class="hljs-built_in">set</span> greet hello
&gt; append greet _world
&gt; get greet               <span class="hljs-comment"># hello_world</span>
&gt; strlen greet            <span class="hljs-comment"># 11</span>

&gt; <span class="hljs-built_in">set</span> i 100
&gt; incr i                  <span class="hljs-comment"># 101</span>
&gt; incrBy i 10             <span class="hljs-comment"># 111</span>
&gt; decr i                  <span class="hljs-comment"># 110</span>
&gt; decrBy i 10             <span class="hljs-comment"># 100</span>
</code></pre>
<ul>
<li>hash</li>
</ul>
<pre><code class="lang-sh">&gt; hmset country china zhonggguo
&gt; hmset country america meiguo

&gt; hmget country china     <span class="hljs-comment"># zhongguo</span>
&gt; hmget country america   <span class="hljs-comment"># meiguo</span>
</code></pre>
<ul>
<li>list</li>
</ul>
<pre><code class="lang-sh">&gt; rpush nums 2 3 4 5
&gt; lpush nums 1

<span class="hljs-comment"># 1 2 3 4 5</span>
&gt; lrange 0 4
</code></pre>
<ul>
<li>set </li>
</ul>
<pre><code class="lang-sh">&gt; sadd box 1 1 1 1 3 3 3 2

<span class="hljs-comment"># 1 2 3</span>
&gt; smembers box
</code></pre>
<ul>
<li>zset</li>
</ul>
<pre><code class="lang-sh">&gt; zadd rank 10 nginx
&gt; zadd rank 1 mysql
&gt; zadd rank 100 redis

<span class="hljs-comment"># mysql nginx redis</span>
&gt; zrangebyscore rank 1 100
</code></pre>
<h3 id="3-&#x547D;&#x4EE4;">3. &#x547D;&#x4EE4;</h3>
<p>&#x767B;&#x9646;</p>
<p><code>redis-cli -h 127.0.0.1 -p 6379 -a 1234</code></p>
<p>&#x666E;&#x901A;&#x952E;&#x64CD;&#x4F5C;</p>
<table>
<thead>
<tr>
<th>cmd</th>
<th>effect</th>
</tr>
</thead>
<tbody>
<tr>
<td>type {key}</td>
<td>&#x83B7;&#x53D6; {key} &#x7684;&#x6570;&#x636E;&#x7ED3;&#x6784;</td>
</tr>
<tr>
<td>keys {pattern}</td>
<td>&#x5217;&#x51FA;&#x6240;&#x6709;&#x5339;&#x914D; {pattern} &#x7684;&#x952E;&#xFF08;&#x5E38;&#x89C1;&#x7684; pattern &#x4E3A; *&#xFF09;</td>
</tr>
<tr>
<td>exists {key}</td>
<td>&#x662F;&#x5426;&#x5B58;&#x5728;&#x952E;&#x4E3A; {key} &#x7684;&#x6570;&#x636E;&#x7ED3;&#x6784;</td>
</tr>
<tr>
<td>del {key}</td>
<td>&#x5220;&#x9664; {key}</td>
</tr>
<tr>
<td>flushdb</td>
<td>&#x5220;&#x9664;&#x5F53;&#x524D;&#x6570;&#x636E;&#x5E93;&#x7684;&#x6240;&#x6709;&#x952E;</td>
</tr>
<tr>
<td>flushall</td>
<td>&#x5220;&#x9664;&#x6240;&#x6709;&#x6570;&#x636E;&#x5E93;&#x7684;&#x6240;&#x6709;&#x952E;</td>
</tr>
</tbody>
</table>
<p>&#x91CD;&#x547D;&#x540D;</p>
<table>
<thead>
<tr>
<th>cmd</th>
<th>effect</th>
</tr>
</thead>
<tbody>
<tr>
<td>rename {old_key} {new_key}</td>
<td>&#x5C06; {old_key} &#x547D;&#x540D;&#x4E3A; {new_key}&#xFF0C;&#x5373;&#x4F7F; {new_key} &#x5B58;&#x5728;&#x4E5F;&#x8986;&#x76D6;</td>
</tr>
<tr>
<td>renamenx {old_key} {new_key}</td>
<td>&#x5C06; {old_key} &#x547D;&#x540D;&#x4E3A; {new_key}&#xFF0C;&#x5982;&#x679C; {new_key} &#x5B58;&#x5728;&#x5219;&#x5931;&#x8D25;</td>
</tr>
</tbody>
</table>
<p>&#x8FC7;&#x671F;&#xFF08;&#x5355;&#x4F4D;&#x4E3A;&#x79D2;&#xFF09;</p>
<table>
<thead>
<tr>
<th>cmd</th>
<th>effect</th>
</tr>
</thead>
<tbody>
<tr>
<td>expire {key} 5</td>
<td>5 &#x79D2;&#x540E;&#x5220;&#x9664; {key}</td>
</tr>
<tr>
<td>ttl {key}</td>
<td>&#x83B7;&#x53D6; {key} &#x5269;&#x4F59;&#x5B58;&#x6D3B;&#x65F6;&#x95F4;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x4F7F;&#x7528; expire &#x8BBE;&#x7F6E;&#x8FC7;&#x671F;&#x65F6;&#x95F4;&#xFF0C;&#x5219;&#x4E3A; -1</td>
</tr>
<tr>
<td>persist {key}</td>
<td>&#x6E05;&#x9664; {key} &#x7684; expire &#x8FC7;&#x671F;&#x65F6;&#x95F4;</td>
</tr>
</tbody>
</table>
<p>&#x8FDE;&#x63A5;</p>
<table>
<thead>
<tr>
<th>cmd</th>
<th>effect</th>
</tr>
</thead>
<tbody>
<tr>
<td>auth</td>
<td>&#x5BC6;&#x7801;&#x9A8C;&#x8BC1;</td>
</tr>
<tr>
<td>select {n}</td>
<td>&#x9009;&#x62E9;&#x7B2C; {n} &#x4E2A;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x9ED8;&#x8BA4;&#x662F; 0</td>
</tr>
<tr>
<td>ping</td>
<td>&#x6D4B;&#x8BD5;&#x8FDE;&#x63A5;&#xFF0C;&#x5982;&#x679C;&#x8FD4;&#x56DE; pong &#x5219;&#x6B63;&#x5E38;&#xFF0C;&#x5426;&#x5219;&#x8868;&#x793A;&#x8FDE;&#x63A5;&#x5DF2;&#x7ECF;&#x65AD;&#x5F00;</td>
</tr>
<tr>
<td>quit</td>
<td>&#x9000;&#x51FA;&#x5F53;&#x524D;&#x8FDE;&#x63A5;</td>
</tr>
</tbody>
</table>
<p>&#x670D;&#x52A1;&#x7AEF;</p>
<table>
<thead>
<tr>
<th>cmd</th>
<th>effect</th>
</tr>
</thead>
<tbody>
<tr>
<td>info</td>
<td>&#x83B7;&#x53D6;&#x670D;&#x52A1;&#x5668;&#x72B6;&#x6001;&#x4FE1;&#x606F;</td>
</tr>
<tr>
<td>client list</td>
<td>&#x83B7;&#x53D6;&#x6240;&#x6709;&#x5BA2;&#x6237;&#x7AEF;&#x4FE1;&#x606F;</td>
</tr>
<tr>
<td>client setname</td>
<td>&#x8BBE;&#x7F6E;&#x5F53;&#x524D;&#x8FDE;&#x63A5;&#x7684;&#x540D;&#x5B57;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; client list &#x770B;&#x51FA;</td>
</tr>
<tr>
<td>client kill id {id}</td>
<td>&#x901A;&#x8FC7; {id} &#x65AD;&#x5F00;&#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x8FDE;&#x63A5;&#xFF0C;{id} &#x53EF;&#x4EE5;&#x901A;&#x8FC7; client list &#x5F97;&#x5230;</td>
</tr>
</tbody>
</table>
<p>&#x5176;&#x4ED6;</p>
<table>
<thead>
<tr>
<th>cmd</th>
<th>effect</th>
</tr>
</thead>
<tbody>
<tr>
<td>command</td>
<td>&#x83B7;&#x53D6;&#x6240;&#x6709;&#x547D;&#x4EE4;</td>
</tr>
<tr>
<td>command count</td>
<td>&#x83B7;&#x53D6;&#x547D;&#x4EE4;&#x7684;&#x6570;&#x91CF;</td>
</tr>
<tr>
<td>command get {cmd}</td>
<td>&#x83B7;&#x53D6; {cmd} &#x547D;&#x4EE4;&#x7684;&#x76F8;&#x5173;&#x4FE1;&#x606F;</td>
</tr>
<tr>
<td>config get {config_key}</td>
<td>&#x83B7;&#x53D6; {config_key} &#x7684;&#x914D;&#x7F6E;&#xFF0C;&#x5982; <code>config get dir</code> &#x83B7;&#x53D6; redis &#x5B89;&#x88C5;&#x76EE;&#x5F55;</td>
</tr>
<tr>
<td>config set {config_key} {config_value}</td>
<td>&#x914D;&#x7F6E; {config_key} &#x7684;&#x503C;&#x4E3A; {config_value}</td>
</tr>
<tr>
<td>debug object {key}</td>
<td>&#x83B7;&#x53D6; {key} &#x7684;&#x8C03;&#x8BD5;&#x4FE1;&#x606F;</td>
</tr>
<tr>
<td>debug segfault</td>
<td>&#x624B;&#x52A8;&#x4F7F;&#x670D;&#x52A1;&#x7AEF;&#x5954;&#x6E83;</td>
</tr>
<tr>
<td>monitor</td>
<td>&#x76D1;&#x63A7;&#x83B7;&#x53D6;&#x6240;&#x6709;&#x53D1;&#x9001;&#x5230;&#x670D;&#x52A1;&#x7AEF;&#x7684;&#x547D;&#x4EE4;</td>
</tr>
<tr>
<td>save</td>
<td>&#x624B;&#x52A8;&#x4FDD;&#x5B58;&#x5185;&#x5B58;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x5230;&#x786C;&#x76D8;</td>
</tr>
<tr>
<td>bgsave</td>
<td>&#x540E;&#x53F0;&#x4FDD;&#x5B58;&#x5185;&#x5B58;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x5230;&#x786C;&#x76D8;</td>
</tr>
<tr>
<td>role</td>
<td>&#x83B7;&#x53D6;&#x670D;&#x52A1;&#x7AEF;&#x7684;&#x89D2;&#x8272;&#xFF0C;master or slave</td>
</tr>
</tbody>
</table>
<h3 id="4-&#x5176;&#x4ED6;">4. &#x5176;&#x4ED6;</h3>
<h4 id="hyperloglog">HyperLogLog</h4>
<p>&#x5728; Redis &#x91CC;&#x9762;&#xFF0C;&#x6BCF;&#x4E2A; HyperLogLog &#x952E;&#x53EA;&#x9700;&#x8981;&#x82B1;&#x8D39; 12 KB &#x5185;&#x5B58;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x8BA1;&#x7B97;&#x63A5;&#x8FD1; 2^64 &#x4E2A;&#x4E0D;&#x540C;&#x5143;&#x7D20;&#x7684;&#x57FA; &#x6570;&#x3002;&#x8FD9;&#x548C;&#x8BA1;&#x7B97;&#x57FA;&#x6570;&#x65F6;&#xFF0C;&#x5143;&#x7D20;&#x8D8A;&#x591A;&#x8017;&#x8D39;&#x5185;&#x5B58;&#x5C31;&#x8D8A;&#x591A;&#x7684;&#x96C6;&#x5408;&#x5F62;&#x6210;&#x9C9C;&#x660E;&#x5BF9;&#x6BD4;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x56E0;&#x4E3A; HyperLogLog &#x53EA;&#x4F1A;&#x6839;&#x636E;&#x8F93;&#x5165;&#x5143;&#x7D20;&#x6765;&#x8BA1;&#x7B97;&#x57FA;&#x6570;&#xFF0C;&#x800C;&#x4E0D;&#x4F1A;&#x50A8;&#x5B58;&#x8F93;&#x5165;&#x5143;&#x7D20;&#x672C;&#x8EAB;&#x3002;</p>
<p>HyperLogLog &#x76F8;&#x5F53;&#x4E8E; Set &#x7684; size&#x3002;</p>
<pre><code class="lang-sh"><span class="hljs-comment"># [1, 1, 1, 2, 2, 3] -&gt; [1, 2, 3] -&gt; 3</span>

&gt; pfadd k 1 1 1 2 2 3
&gt; pfcount k               <span class="hljs-comment"># 3</span>
</code></pre>
<h4 id="&#x53D1;&#x5E03;&#x8BA2;&#x9605;">&#x53D1;&#x5E03;&#x8BA2;&#x9605;</h4>
<p>&#x76D1;&#x542C;&#x540C;&#x4E00;&#x4E2A; redis &#x670D;&#x52A1;&#x5668;&#x7684;&#x4E0D;&#x540C;&#x5BA2;&#x6237;&#x7AEF;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x53D1;&#x5E03;&#xFF08;publish&#xFF09;&#x548C;&#x8BA2;&#x9605;&#xFF08;subscribe&#xFF09;&#x8FDB;&#x884C;&#x6D88;&#x606F;&#x5BF9;&#x8BDD;</p>
<pre><code class="lang-sh">&gt; publish triski hello
&gt; publish triski world

<span class="hljs-comment"># &#x6240;&#x6709;&#x6267;&#x884C; subscribe triski &#x7684;&#x5BA2;&#x6237;&#x7AEF;&#x90FD;&#x4F1A;&#x6536;&#x5230; hello &#x548C; world</span>
</code></pre>
<h4 id="&#x4E8B;&#x52A1;&#xFF08;&#x6279;&#x5904;&#x7406;&#xFF09;">&#x4E8B;&#x52A1;&#xFF08;&#x6279;&#x5904;&#x7406;&#xFF09;</h4>
<ul>
<li>Redis &#x4E8B;&#x52A1;&#x7684;&#x6267;&#x884C;&#x8FC7;&#x7A0B;&#xFF1A;&#x5F00;&#x59CB;&#x4E8B;&#x52A1;&#xFF08;multi&#xFF09;&#x300B; &#x547D;&#x4EE4;&#x5165;&#x961F;&#xFF08;&#x5E76;&#x4E0D;&#x9A6C;&#x4E0A;&#x6267;&#x884C;&#xFF09; &#x300B; &#x6267;&#x884C;&#x4E8B;&#x52A1;&#xFF08;exec&#xFF09;</li>
<li>Redis &#x7684;&#x4E8B;&#x52A1;&#x5E76;&#x4E0D;&#x5177;&#x5907;&#x539F;&#x5B50;&#x6027;&#xFF0C;&#x6548;&#x679C;&#x7B49;&#x540C;&#x4E8E;&#x6279;&#x5904;&#x7406;&#xFF0C;&#x5982;&#x679C;&#x4E2D;&#x95F4;&#x6709;&#x4E00;&#x6761;&#x6267;&#x884C;&#x5931;&#x8D25;&#xFF0C;&#x5176;&#x4ED6;&#x547D;&#x4EE4;&#x4ECD;&#x4F1A;&#x6B63;&#x5E38;&#x6267;&#x884C;</li>
<li>&#x9664;&#x4E86; multi &#x548C; exec &#x6BD4;&#x8F83;&#x5E38;&#x7528;&#xFF0C;&#x5176;&#x4ED6;&#x76F8;&#x5173;&#x7684;&#x6307;&#x4EE4;&#x8FD8;&#x6709; discard&#xFF08;&#x629B;&#x5F03;&#x4E8B;&#x52A1;&#xFF0C;&#x5220;&#x9664;&#x961F;&#x5217;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x547D;&#x4EE4;&#xFF09;</li>
</ul>
<pre><code class="lang-sh">&gt; multi
&gt; <span class="hljs-built_in">set</span> name chen
&gt; append name _shu
&gt; append name _tian
&gt; get name
&gt; <span class="hljs-built_in">exec</span>

1) OK
2) (<span class="hljs-built_in">integer</span>) 8
3) (<span class="hljs-built_in">integer</span>) 13
4) <span class="hljs-string">&quot;chen_shu_tian&quot;</span>
</code></pre>
<h3 id="5-&#x9AD8;&#x7EA7;">5. &#x9AD8;&#x7EA7;</h3>
<h4 id="&#x5907;&#x4EFD;&#x4E0E;&#x6062;&#x590D;">&#x5907;&#x4EFD;&#x4E0E;&#x6062;&#x590D;</h4>
<p>Redis &#x7684;&#x5907;&#x4EFD;&#x5C31;&#x662F;&#x4FDD;&#x5B58;&#xFF0C;&#x901A;&#x8FC7; save &#x6216; bgsave&#xFF0C;&#x4F1A;&#x5C06;&#x6570;&#x636E;&#x4FDD;&#x5B58;&#x5230; Redis &#x5B89;&#x88C5;&#x76EE;&#x5F55;&#x4E0B;&#x7684; dump.rdb &#x4E2D;&#xFF0C;&#x6062;&#x590D;&#x5C31;&#x662F;&#x5C06;&#x8FD9;&#x4E2A; rdb &#x6587;&#x4EF6;&#x653E;&#x7F6E;&#x5230; Redis &#x7684;&#x5B89;&#x88C5;&#x76EE;&#x5F55;&#x4E0B;</p>
<h4 id="&#x6027;&#x80FD;&#x6D4B;&#x8BD5;">&#x6027;&#x80FD;&#x6D4B;&#x8BD5;</h4>
<p>&#x4F7F;&#x7528; redis-benchmark &#x5DE5;&#x5177;&#x8FDB;&#x884C;&#x6D4B;&#x8BD5;&#xFF08;&#x4E0E; redis-cli&#xFF0C;redis-server &#x540C;&#x7EA7;&#xFF09;&#xFF0C;&#x4F7F;&#x7528; -h &#x9009;&#x9879;&#x83B7;&#x53D6;&#x66F4;&#x591A;&#x4FE1;&#x606F;&#xFF0C;&#x4E0D;&#x5E26;&#x4EFB;&#x4F55;&#x9009;&#x9879;&#x76F4;&#x63A5;&#x6267;&#x884C;&#x5219;&#x6309;&#x9ED8;&#x8BA4;&#x65B9;&#x6848;&#x8FDB;&#x884C;&#x6D4B;&#x8BD5;</p>
<pre><code class="lang-sh"><span class="hljs-comment"># &#x5BF9; get&#xFF0C;lpush&#xFF0C;zadd &#x4E09;&#x4E2A;&#x547D;&#x4EE4;&#x8FDB;&#x884C; 1000 &#x6B21;&#x6D4B;&#x8BD5;</span>
&gt; redis-benchmark -n 1000 -t get,lpush,zadd
</code></pre>
<hr>
<h3 id="0-&#x9ED8;&#x8BA4;&#x914D;&#x7F6E;">0. &#x9ED8;&#x8BA4;&#x914D;&#x7F6E;</h3>
<pre><code class="lang-sh"><span class="hljs-built_in">bind</span> 127.0.0.1
port 6379

<span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x5BC6;&#x7801;, &#x8BBE;&#x7F6E;&#x4E4B;&#x540E;&#x9700;&#x8981;&#x4F7F;&#x7528; auth &#x8FDB;&#x884C;&#x9A8C;&#x8BC1;</span>
<span class="hljs-comment"># requirepass 0009</span>

<span class="hljs-comment"># &#x6307;&#x5B9A;&#x5BA2;&#x6237;&#x7AEF;&#x95F2;&#x7F6E;&#x591A;&#x957F;&#x65F6;&#x95F4;&#x540E;&#x65AD;&#x5F00;&#x8FDE;&#x63A5;, &#x4E3A; 0 &#x5219;&#x4E0D;&#x9650;&#x5236;</span>
timeout 0

<span class="hljs-comment"># &#x65E5;&#x5FD7;&#x7B49;&#x7EA7;&#x53CA;&#x65E5;&#x5FD7;&#x4FDD;&#x5B58;&#x4F4D;&#x7F6E;</span>
loglevel notice
logfile <span class="hljs-string">&quot;server_log.txt&quot;</span>

<span class="hljs-comment"># &#x6570;&#x636E;&#x5E93;&#x6570;&#x91CF;, &#x9ED8;&#x8BA4;&#x6570;&#x636E;&#x5E93;&#x4E3A; 0, &#x4F7F;&#x7528; select ${index} &#x53EF;&#x4EE5;&#x8DF3;&#x5230;&#x6307;&#x5B9A;&#x6570;&#x636E;&#x5E93;</span>
databases 16

<span class="hljs-comment"># save &lt;seconds&gt; &lt;changes_count&gt;, &#x5F53; ${sceonds} &#x5185;&#x6709; ${changes_count} &#x6B21;&#x66F4;&#x65B0;&#x65F6;, &#x5C06;&#x6570;&#x636E;&#x540C;&#x6B65;&#x5230;&#x6570;&#x636E;&#x6587;&#x4EF6;&#x4E2D;</span>
save 900 1
save 300 10
save 60 10000

<span class="hljs-comment"># &#x6307;&#x5B9A;&#x662F;&#x5426;&#x5728;&#x6BCF;&#x6B21;&#x66F4;&#x65B0;&#x64CD;&#x4F5C;&#x540E;&#x8FDB;&#x884C;&#x65E5;&#x5FD7;&#x8BB0;&#x5F55;&#xFF0C;Redis &#x5728;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#x662F;&#x5F02;&#x6B65;&#x7684;&#x628A;&#x6570;&#x636E;&#x5199;&#x5165;&#x78C1;&#x76D8;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x5F00;&#x542F;&#xFF0C;&#x53EF;&#x80FD;&#x4F1A;&#x5728;&#x65AD;&#x7535;&#x65F6;&#x5BFC;&#x81F4;&#x4E00;&#x6BB5;&#x65F6;&#x95F4;&#x5185;&#x7684;&#x6570;&#x636E;&#x4E22;&#x5931;&#x3002;</span>
<span class="hljs-comment"># &#x56E0;&#x4E3A; redis &#x672C;&#x8EAB;&#x540C;&#x6B65;&#x6570;&#x636E;&#x6587;&#x4EF6;&#x662F;&#x6309;&#x4E0A;&#x9762; save &#x6761;&#x4EF6;&#x6765;&#x540C;&#x6B65;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x6709;&#x7684;&#x6570;&#x636E;&#x4F1A;&#x5728;&#x4E00;&#x6BB5;&#x65F6;&#x95F4;&#x5185;&#x53EA;&#x5B58;&#x5728;&#x4E8E;&#x5185;&#x5B58;&#x4E2D;&#x3002;&#x9ED8;&#x8BA4;&#x4E3A; no</span>
appendonly no
appendfilename <span class="hljs-string">&quot;appendonly.aof&quot;</span>
appendfsync everysec

<span class="hljs-comment"># &#x6307;&#x5B9A;&#x5B58;&#x50A8;&#x81F3;&#x672C;&#x5730;&#x6570;&#x636E;&#x5E93;&#x65F6;&#x662F;&#x5426;&#x538B;&#x7F29;&#x6570;&#x636E;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A; yes&#xFF0C;Redis &#x91C7;&#x7528; LZF &#x538B;&#x7F29;&#xFF0C;&#x5982;&#x679C;&#x4E3A;&#x4E86;&#x8282;&#x7701; CPU &#x65F6;&#x95F4;&#xFF0C;&#x53EF;&#x4EE5;&#x5173;&#x95ED;&#x8BE5;&#x9009;&#x9879;&#xFF0C;&#x4F46;&#x4F1A;&#x5BFC;&#x81F4;&#x6570;&#x636E;&#x5E93;&#x6587;&#x4EF6;&#x53D8;&#x7684;&#x5DE8;&#x5927;</span>
rdbcompression yes

<span class="hljs-comment"># &#x672C;&#x5730;&#x6570;&#x636E;&#x5E93;&#x6587;&#x4EF6;&#x540D;&#x53CA;&#x5B58;&#x653E;&#x4F4D;&#x7F6E;</span>
dbfilename dump.rdb
dir ./

<span class="hljs-comment">######################################### &#x5176;&#x4ED6; #########################################</span>

protected-mode yes
tcp-backlog 511
tcp-keepalive 0
syslog-enabled yes
syslog-ident redis
stop-writes-on-bgsave-error yes
rdbchecksum yes
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events <span class="hljs-string">&quot;&quot;</span>
<span class="hljs-built_in">hash</span>-max-ziplist-entries 512
<span class="hljs-built_in">hash</span>-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
<span class="hljs-built_in">set</span>-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
</code></pre>

                                
                                </section>
                            
                        </div>
                    </div>
                
            </div>

            
                
                <a href="oracle.html" class="navigation navigation-prev " aria-label="Previous page: oracle">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="script.html" class="navigation navigation-next " aria-label="Next page: script">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"redis","level":"1.5.10","depth":2,"next":{"title":"script","level":"1.5.11","depth":2,"path":"soft_skills/script.md","ref":"soft_skills/script.md","articles":[]},"previous":{"title":"oracle","level":"1.5.9","depth":2,"path":"soft_skills/oracle.md","ref":"soft_skills/oracle.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["-search","-sharing","-lunr"],"pluginsConfig":{"highlight":{},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"soft_skills/redis.md","mtime":"2020-01-22T15:06:53.381Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-03-17T16:45:36.070Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

